home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / scale_geom / hips.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-17  |  4.8 KB  |  265 lines

  1. /*
  2.  * hips: subroutine package to read and write hips images
  3.  */
  4.  
  5. static char rcsid[] = "$Header$ ";
  6.  
  7. #include "hips.h"
  8. #include "simple.h"
  9. #include "pixel.h"
  10.  
  11. #define Calloc(a,b) (b *) calloc((unsigned)(a), sizeof(b))
  12.  
  13. extern struct header hd;
  14. /****************************************/
  15. Hips
  16. * hips_open(file, mode)
  17.     char     *file, *mode;
  18. {
  19.     Hips     *p;
  20.     int       sz;
  21.  
  22.     ALLOC_ZERO(p, Hips, 1);
  23.  
  24.     strcpy(p->name, file);
  25.     p->nchan = 1;
  26.     p->ox = 0;
  27.     p->oy = 0;
  28.  
  29.     if (str_eq(mode, "r")) {    /* input file */
  30.     read_header(&hd);
  31.     if (hd.pixel_format != PFBYTE) {
  32.         fprintf(stderr, "scale_geom: pixel format must be byte\n");
  33.         exit(1);
  34.     }
  35.     p->dx = hd.ocols;
  36.     p->dy = hd.orows;
  37.     sz = hd.orows * hd.ocols;
  38.     } else {            /* maximum output file */
  39.     p->dx = XMAX;
  40.     p->dy = YMAX;
  41.     sz = XMAX * YMAX;
  42.     }
  43.  
  44.     if ((p->ibuf = Calloc(sz, Pixel1)) == NULL) {
  45.     fprintf(stderr, "memory allocation error \n");
  46.     exit(1);
  47.     }
  48.     return p;
  49. }
  50.  
  51. /**********************************************/
  52. void
  53. hips_close(p)
  54.     Hips     *p;
  55. {
  56.     fprintf(stderr, "Not needed: using stdin and stdout \n");
  57.     exit(1);
  58. }
  59.  
  60. /****************************************/
  61. char     *
  62. hips_get_name(p)
  63.     Hips     *p;
  64. {
  65.     return p->name;
  66. }
  67.  
  68. /****************************************/
  69. void
  70. hips_clear(p, pv)
  71.     Hips     *p;
  72.     Pixel1    pv;
  73. {
  74.     return;
  75. }
  76.  
  77. /****************************************/
  78. void
  79. hips_clear_rgba(p, r, g, b, a)
  80.     Hips     *p;
  81.     Pixel1    r, g, b, a;
  82. {
  83.     return;
  84. }
  85.  
  86. /*-------------------- file writing routines --------------------*/
  87. void
  88. hips_set_nchan(p, nchan)
  89.     Hips     *p;
  90.     int       nchan;
  91. {
  92.     p->nchan = nchan;
  93. }
  94.  
  95. /****************************************/
  96. void
  97. hips_set_box(p, ox, oy, dx, dy)
  98.     Hips     *p;
  99.     int       ox, oy, dx, dy;
  100. {
  101.     p->ox = ox;
  102.     p->oy = oy;
  103.     if (dx > XMAX || dy > YMAX) {
  104.     fprintf(stderr, "\n Error: Maximum destination size if %d x %d \n\n",
  105.          XMAX, YMAX);
  106.     exit(-1);
  107.     }
  108.     p->dx = dx;
  109.     p->dy = dy;
  110. }
  111.  
  112. /****************************************/
  113. void
  114. hips_write_pixel(p, x, y, pv)
  115.     Hips     *p;
  116.     int       x, y;
  117.     Pixel1    pv;
  118. {
  119.     fprintf(stderr, "hips_write_pixel: unimplemented\n");
  120.     exit(1);
  121. }
  122.  
  123. /****************************************/
  124. void
  125. hips_write_pixel_rgba(p, x, y, r, g, b, a)
  126.     Hips     *p;
  127.     int       x, y;
  128.     Pixel1    r, g, b, a;
  129. {
  130.     fprintf(stderr, "hips_write_pixel_rgba: unimplemented\n");
  131.     exit(1);
  132. }
  133.  
  134. /****************************************/
  135. void
  136. hips_write_row(p, y, x0, nx, buf)
  137.     Hips     *p;
  138.     int       y, x0, nx;
  139.     register Pixel1 *buf;
  140. {
  141.  
  142.     int       offset, i;
  143.  
  144.     offset = (y * p->dx) + x0;
  145.  
  146.     for (i = 0; i < nx; i++) {
  147.     p->ibuf[offset + i] = buf[i];
  148. /*    fprintf(stderr, " %d", buf[i]); */
  149.     }
  150. }
  151.  
  152. /****************************************/
  153. void
  154. hips_write_row_rgba(p, y, x0, nx, buf)
  155.     Hips     *p;
  156.     int       y, x0, nx;
  157.     register Pixel1 *buf;
  158. {
  159.     fprintf(stderr, "hips_write_row_rgba: unimplemented\n");
  160.     exit(1);
  161. }
  162.  
  163. /*-------------------- file reading routines --------------------*/
  164.  
  165. int
  166. hips_get_nchan(p)
  167.     Hips     *p;
  168. {
  169.     return p->nchan;
  170. }
  171.  
  172. /****************************************/
  173. void
  174. hips_get_box(p, ox, oy, dx, dy)
  175.     Hips     *p;
  176.     int      *ox, *oy, *dx, *dy;
  177. {
  178.     *ox = p->ox;
  179.     *oy = p->oy;
  180.     *dx = p->dx;
  181.     *dy = p->dy;
  182. }
  183.  
  184. /****************************************/
  185. Pixel1
  186. hips_read_pixel(p, x, y)
  187.     Hips     *p;
  188.     int       x, y;
  189. {
  190.     fprintf(stderr, "hips_read_pixel: unimplemented\n");
  191.     exit(1);
  192. }
  193.  
  194. /****************************************/
  195. void
  196. hips_read_pixel_rgba(p, x, y, pv)
  197.     Hips     *p;
  198.     int       x, y;
  199.     Pixel1   *pv;
  200. {
  201.     fprintf(stderr, "hips_read_pixel_rgba: unimplemented\n");
  202.     exit(1);
  203. }
  204.  
  205. /****************************************/
  206. void
  207. hips_read_row(p, y, x0, nx, buf)
  208.     Hips     *p;
  209.     int       y, x0, nx;
  210.     Pixel1   *buf;
  211. {
  212.     int       offset, i;
  213.  
  214.     offset = (y * p->dx) + x0;
  215.  
  216.     for (i = 0; i < nx; i++) {
  217.     buf[i] = p->ibuf[offset + i];
  218.     /* fprintf(stderr, " %d", buf[i]); */
  219.     }
  220.  
  221. }
  222.  
  223. /****************************************/
  224. void
  225. hips_read_row_rgba(p, y, x0, nx, buf)
  226.     Hips     *p;
  227.     int       y, x0, nx;
  228.     Pixel1   *buf;
  229. {
  230.     fprintf(stderr, "hips_read_row_rgba: unimplemented\n");
  231.     exit(1);
  232. }
  233.  
  234. /****************************************/
  235. /* routines to load and save hips file */
  236. /****************************************/
  237. void
  238. load_hips_frame(p)
  239.     Hips     *p;
  240. {
  241.     int       length;
  242.  
  243.     length = p->dx * p->dy * sizeof(Pixel1);
  244.  
  245.     if (fread(p->ibuf, length,1,stdin) != 1) {
  246.     fprintf(stderr, "error during read\n");
  247.     exit(1);
  248.     }
  249. }
  250.  
  251. /****************************************/
  252. void
  253. store_hips_frame(p)
  254.     Hips     *p;
  255. {
  256.     int       length;
  257.  
  258.     length = p->dx * p->dy * sizeof(Pixel1);
  259.  
  260.     if (fwrite(p->ibuf, length,1,stdout) != 1) {
  261.     fprintf(stderr, "error during write\n");
  262.     exit(1);
  263.     }
  264. }
  265.